home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Devices / CD-ROM / iso9660 / Srcs / i_o.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-28  |  4.7 KB  |  202 lines  |  [TEXT/MPS ]

  1. /************************************************************************
  2.  *
  3.  *    Copyright © 1990    Apple Computer, Inc.  All rights reserved.
  4.  *
  5.  ************************************************************************/
  6.  
  7. #include <stdio.h>
  8. #include <Types.h>
  9. #include <ToolUtils.h>
  10. #include <Quickdraw.h>
  11. #include <Files.h>
  12. #include <Memory.h>
  13.  
  14. #define ISO
  15.  
  16. #include "HighSierra.h"
  17. #include "BuildISO.h"
  18.  
  19. #include "i_o.proto.h"
  20. #include "Support.proto.h"
  21. #include "ErrorMsg.proto.h"
  22.  
  23.  
  24. /************************************************************************
  25.  *
  26.  *  Function:        isoOpen
  27.  *
  28.  *  Purpose:        Open the driver for i/o
  29.  *
  30.  *  Returns:        OSErr
  31.  *
  32.  *  Side Effects:    fills *RefNum with valid reference number for driver.
  33.  *
  34.  *  Description:    Issue Mac OS PBOpen call to open the driver.  We
  35.  *                    can use the returned reference number to access the
  36.  *                    driver for raw i/o.
  37.  *
  38.  *
  39.  ************************************************************************/
  40. OSErr
  41. isoOpen(StringPtr fn, short *RefNum)
  42. {
  43.     ParamBlockRec    pb;
  44.     OSErr    result;
  45.     
  46.     pb.ioParam.ioNamePtr = fn;
  47.     pb.ioParam.ioCompletion = 0;
  48.     pb.ioParam.ioPermssn = fsRdPerm;
  49.     result = PBOpen(&pb, false);
  50.     *RefNum = pb.ioParam.ioRefNum;
  51.     
  52.     return result;
  53. }
  54.  
  55. /************************************************************************
  56.  *
  57.  *  Function:    isoRead
  58.  *
  59.  *  Purpose:    read from the driver
  60.  *
  61.  *  Returns:    OSErr
  62.  *
  63.  *  Side Effects:    fills dest with contents for 'count' bytes.
  64.  *
  65.  *  Description:    do a call to the Mac CD driver to read a specified
  66.  *                    number of bytes starting at 'offset'.  The number of
  67.  *                    bytes must be a multiple of 512, or this call won't
  68.  *                    work (the driver returns an error)
  69.  *
  70.  ************************************************************************/
  71. OSErr
  72. isoRead(short referenceNumber, Ptr dest, long count, long offset)
  73. {
  74.     OSErr result;
  75.     ParamBlockRec    io;
  76.     
  77.     ClearOut((char *)&io, sizeof(io));
  78.     io.ioParam.ioCompletion = NULL;
  79.     io.ioParam.ioVRefNum = 0;
  80.     io.ioParam.ioRefNum = referenceNumber;
  81.     io.ioParam.ioBuffer = dest;
  82.     io.ioParam.ioReqCount = count;
  83.     io.ioParam.ioPosMode = fsFromStart;
  84.     io.ioParam.ioPosOffset = offset;
  85.     result = PBRead(&io, false);
  86.     
  87.     if (result != noErr)
  88.         ErrorMsg("PBRead failed. ioActCount = %d", io.ioParam.ioActCount);
  89.     
  90.     return result;
  91. }
  92.  
  93.  
  94. /************************************************************************
  95.  *
  96.  *  Function:    isoWrite
  97.  *
  98.  *  Purpose:    Write to the driver
  99.  *
  100.  *  Returns:    OSErr
  101.  *
  102.  *  Side Effects:    none
  103.  *
  104.  *  Description:    do a call to the Mac CD driver to write a specified
  105.  *                    number of bytes starting at 'offset'.  The number of
  106.  *                    bytes must be a multiple of 512, or this call won't
  107.  *                    work (the driver returns an error.)
  108.  *
  109.  ************************************************************************/
  110. OSErr
  111. isoWrite(short referenceNumber, Ptr buffer, long count, long offset)
  112. {
  113.     OSErr result;
  114.     ParamBlockRec    io;
  115.     
  116.     ClearOut((char *)&io, sizeof(io));
  117.     io.ioParam.ioCompletion = NULL;
  118.     io.ioParam.ioVRefNum = 1;
  119.     io.ioParam.ioRefNum = referenceNumber;
  120.     io.ioParam.ioBuffer = buffer;
  121.     io.ioParam.ioReqCount = count;
  122.     io.ioParam.ioPosMode = fsFromStart;
  123.     io.ioParam.ioPosOffset = offset;
  124.     result = PBWrite(&io, false);
  125.     
  126.     if (result != noErr)
  127.         ErrorMsg("PBWrite failed. result = %d", result);
  128.     
  129.     return result;
  130. }
  131.  
  132.  
  133. /************************************************************************
  134.  *
  135.  *  Function:        ZeroDisk
  136.  *
  137.  *  Purpose:        Clean out this disk so it's not HFS anymore
  138.  *
  139.  *  Returns:        OSErr
  140.  *
  141.  *  Side Effects:    zero out a lot of disk
  142.  *
  143.  *  Description:    loop, doing a write of zeros.
  144.  *
  145.  ************************************************************************/
  146. OSErr
  147. ZeroDisk(short referenceNumber)
  148. {
  149.     Ptr        noBuffer;
  150.     short    i;
  151.     short    j;
  152.     OSErr    result;
  153.     CursHandle    cursor;
  154.     
  155.     noBuffer = NewPtr(CDBLKSIZE);
  156.     if (noBuffer == NULL)
  157.         return (MemError());
  158.     for (i = 0; i < CDBLKSIZE; i++)
  159.         noBuffer[i] = 0;
  160.  
  161.     result = noErr;
  162.  
  163.      cursor = GetCursor(watchCursor);
  164.      if (!cursor)
  165.          SetCursor(*cursor);
  166.     for (i = 0, j = 0; i < 10 && result == noErr; i++, j++)
  167.         result = isoWrite(referenceNumber, noBuffer, (long)CDBLKSIZE, (long) j*CDBLKSIZE);
  168.     
  169.     SetCursor(&qd.arrow);
  170.     DisposPtr(noBuffer);
  171.     return result;
  172. }
  173.  
  174. /************************************************************************
  175.  *
  176.  *  Function:        GetDriveNumber
  177.  *
  178.  *  Purpose:        Get the driver number
  179.  *
  180.  *  Returns:        short.  The driver number
  181.  *
  182.  *  Side Effects:    none.
  183.  *
  184.  *  Description:    PBHGetVInfo() will retrieve the driver
  185.  *                    number, given the vRefNum associated with a file.
  186.  *
  187.  ************************************************************************/
  188. short
  189. GetDriveNumber(short vRefNum)
  190. {
  191.     HParamBlockRec    io;
  192.     
  193.     io.volumeParam.ioCompletion = NULL;
  194.     io.volumeParam.ioNamePtr = NULL;
  195.     io.volumeParam.ioVRefNum = vRefNum;
  196.     io.volumeParam.ioVolIndex = 0;
  197.     PBHGetVInfo(&io, false);
  198.     return io.volumeParam.ioVDrvInfo;
  199. }
  200.  
  201.  
  202.